#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200005;

int n, color[MAXN], t, c[MAXN];


int dfs(int k, int col){
    if(k == n + 1) return 0;
    c[k] = col;
    int ans = 0;
    if(k != 1)
        for(int i = k - 1; i >= 1; i--){
            if(c[i] == col){
                if(color[i] == color[k]) ans = color[k];
                break;
            }
        }
    int tmp1 = dfs(k + 1, 0);
    int tmp2 = dfs(k + 1, 1);
    return ans + max(tmp1, tmp2);
}

int main() {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> t;
    while(t--){
        cin >> n;
        for(int i = 1; i <= n; i++){
            cin >> color[i];
        }
        int tmp1 = dfs(1, 0);
        int tmp2 = dfs(1, 1);
        cout << max(tmp1, tmp2) << endl;

        /*cin >> n;
        memset(pos, -1, sizeof(pos));
        for(int i = 1; i <= n; i++){
            cin >> color[i];
            if(p[color[i]] == 0) p[color[i]] = i;
            else {
                pos[i] = p[color[i]];
                p[color[i]] = 0;
            }
        }
        for(int i = 1; i <= n; i++){
            if(pos[i] != -1){
                dp[i][0] = mans ax(dp[i - 1][0], dp[i - 1][1]);
                dp[i][1] = dp[i][0];
            }
        }
        cout << max(dp[n][1], dp[n][0]) << endl;*/
        //memset(p, 0, sizeof(p));
        //memset(dp, 0, sizeof(dp));
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
